//app.js
const config = require('/evn/index.js')
const env = 'Prod'; //Dev Prod
App.config = config[env];

import {
  request,
  requestHasToken
} from '/service/network.js'
App({
  onLaunch: function () {
    wx.login({
      success: (res) => {
        if (res.code) {
          var d = this.globalData; //这里存储了appid、secret、token串  
          var l = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + d.appid + '&secret=' + d.secret + '&js_code=' + res.code + '&grant_type=authorization_code';
          wx.request({
            url: l,
            data: {},
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  
            // header: {}, // 设置请求的 header  
            success: function (res) {
              var obj = {};
              obj.openid = res.data.openid;
              obj.expires_in = Date.now() + res.data.expires_in;
              // console.log(obj);
              // wx.setStorageSync('user', obj);//存储openid  
              wx.setStorageSync('currentOpenid', obj.openid);//存储openid  
            }
          }); 
        } else {
          console.log('获取用户登录态失败！' + res.errMsg)
        }
      }
    })
  },
  //settings表 view 1 admin和发帖用户转发可见  2 admin转发可见
  globalData: {
    userInfo: null,
    appid: "wxcb3d301e710e400c",
    secret: "878204a15887d191cae6d3bc44882056",
    authority:false,//所有从我这里转发,或者用户admin为1,2都设置为true,
    admin:false, //超级管理员
    normalAdmin:false, //普通系统管理员
  }
})